<?php
declare(strict_types=1);
namespace Service\CommodityService;

use App\Model\CommodityModel\SupplierCommodityTag;
use Service\AppService\IdService;
use Service\BaseService;
use Service\Code\Normal;

class SupplierCommodityTagService extends BaseService
{
    /**
     * 消费队列中新增标签数据
     * @param $tagIds
     * @param $goodsBaseId
     * @return array
     */
    public function insertConsumerTags($tagIds,$goodsBaseId,$isDel=false):array
    {
        if ($isDel){
            SupplierCommodityTag::instance()->where('SupplierCommodityID',$goodsBaseId)->delete();
        }
        $saveTagData = [];
        foreach ($tagIds as $tagId) {
            $saveTagData[] = [
                'ID' => IdService::instance()->getOtherID(),
                'SupplierCommodityID' => $goodsBaseId,
                'TagID' => $tagId,
                'CreateTime' => date('Y-m-d H:i:s')
            ];
        }
        SupplierCommodityTag::instance()->insert($saveTagData);
        return Normal::returnSuccessCode();
    }

}